<?php

include_once(MODEL.'/Repository.php');
class SearchRepository extends Repository
{
    public $collection;
    	public function __construct()
	{
		parent::__construct();				
                $this->collection=$this->DB->selectCollection('Offer');
	}
	
	public function GetListCategory() 
	{
		$this->collection = $this->DB->selectCollection('Category');
		return $this->collection->find();
	}
    public function ListOffer($filter)
    {
       include_once(MODEL.'/OfferModel.php');
       $cursor =  $this->collection->find($filter);
       $listOffer = array();
       While ($cursor->hasNext())
       {
            $offer =  new OfferModel();
            $result = $cursor->getNext();
            $offer->ID = $result['_id'];
            $offer->Name = $result['Name'];
            $offer->Location = $result['Location'];
            $offer->Image = $result['Image'];
            $offer->Description = $result['Description'];
            $offer->CreateDate = $result['CreateDate'];
            $offer->Street = $result['Street'];
            
            $user = $this->DB->selectCollection('Account')->findOne(array('_id' => new MongoId($result['AccountID'])));
			$offer->OwnerID = $user['_id'];
			$offer->OwnerName = $user['FirstName'];
			            
            $listOffer[] = $offer;
       }
       return $listOffer;
    }
}
?>
